﻿<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html>
<head>
	<script src="http://code.jquery.com/jquery.js" type="text/javascript"></script>
	<script src="../../../jquery.tmpl.js" type="text/javascript"></script>
	<link href="../../resources/demos.css" rel="stylesheet" type="text/css" />

	<link href="../../resources/movielist.css" rel="stylesheet" type="text/css" />
	<link href="../../resources/syntaxhighlighter.css" rel="stylesheet" type="text/css" />
	<script src="../../resources/syntaxhighlighter.min.js" type="text/javascript"></script>
</head>
<body>
<a href="../../step-by-step.html">Home</a><br />
<a href="4_each-tag.html">Run</a>

<h3>Demo: Using {{each}} to render repeating sections.</h3>

<!--=================== Demo Section ===================-->

<script id="movieTemplate" type="text/x-jquery-tmpl">
	<tr>
		<td>${Title}</td>
		<td>Languages:
			<em>
				{{each Languages}}
					${$value.Name}
				{{/each}}
			</em>
		</td>
	</tr>
</script>

<table><tbody class="header"><tr><th>Synopsis</th><th>Title</th></tr></tbody>
	<tbody id="movieList"></tbody>
</table>

<script type="text/javascript">

	function namePlusSeparator( name, index, length ){
		var ret = name;
		if ( index < length - 1 ) {
			if ( index === length - 2 ) {
				ret += " and";
			} else {
				ret += ",";
			}
		}
		return ret;
	}

	var movies = [
		{
			Title: "Meet Joe Black",
			Languages: [
				{ Name: "English" },
				{ Name: "French" }
			]
		},
		{
			Title: "Eyes Wide Shut",
			Languages: [
				{ Name: "French" },
				{ Name: "German" },
				{ Name: "Spanish" }
			]
		}
	];

	$( "#movieTemplate" ).tmpl( movies )
		.appendTo( "#movieList" );

</script>

<!--================ End of Demo Section ================-->

<h4>Data:</h4>

<pre class="brush: js;">var movies = [
	{
		Title: "Meet Joe Black",
		Languages: [
			{ Name: "English" },
			{ Name: "French" }
		]
	}
];</pre>

<h4>HTML:</h4>

<pre class="brush: xml;">&lt;script id="movieTemplate" type="text/x-jquery-tmpl">
	&lt;tr>
		&lt;td>${Title}&lt;/td>
		&lt;td>Languages:
			&lt;em>
				{{each Languages}}
					${$value.Name}
				{{/each}}
			&lt;/em>
		&lt;/td>
	&lt;/tr>
&lt;/script></pre>

</body>
</html>
